window.onload = function () {
    var vm = new Vue({
        el: "#indexbox",
        data: {
            show: true,
            count: '',
            timer: null,
            username: "", //手机号
            verifyCode: "", //验证码
            password: "", //密码
            reg: /^1[34578]\d{9}$/,
            cortel:1,
            corpsd:1,
            cornew:1,

        },
        created: function () {

        },
        methods: {
            getCode() {
                if (!this.reg.test(this.username)) {
                    this.cortel=0;
                    return;
                }
                var TIME_COUNT = 120;
                if (!this.timer) {
                    this.count = TIME_COUNT;
                    this.show = false;
                    this.timer = setInterval(() => {
                        if (this.count > 0 && this.count <= TIME_COUNT) {
                            this.count--;
                        } else {
                            this.show = true;
                            clearInterval(this.timer);
                            this.timer = null;
                        }
                    }, 1000)
                    var obj = {
                        type: "2",
                        phone: this.username
                    }
                    login_server.getVerifyCode(obj, function (res) {
                        console.log(res, "====验证码信息====");
                    })
                }
            },
            validation() {
                var $this = this;
                if (!this.reg.test(this.username)) {
                    if(this.verifyCode){
                        this.corpsd=1;
                    }
                    if(this.password){
                        this.cornew=1;
                    }
                    this.cortel=0;
                    return;
                }
                if (!this.verifyCode) {
                    if(this.password){
                        this.cornew=1;
                    }
                    this.cortel=1;
                    this.corpsd=0;
                    return;
                }
                if (!this.password) {
                    this.cortel=1;
                    this.corpsd=1;
                    this.cornew=0;
                    return;
                }
                var obj = {
                    username: this.username,
                    verifyCode: this.verifyCode,
                    password: this.password
                }
                login_server.forgetPassword(obj, function (res) {
                    console.log(res, "====验证码信息====");
                    if(res.data.code==200){
                        $this.reset()
                        window.location.href='../login/loginmodifysuccess.html'
                    }else if(res.data.code==400){
                        $this.corpsd=0;
                        $this.cornew=1;
                    }
                })
            },
            reset(){
                this.cortel=1;
                this.corpsd=1;
                this.cornew=1;
            },

        }
    });
};